refactor
authorJoey Hess <joeyh@joeyh.name>
Wed, 26 Feb 2025 18:05:37 +0000 (14:05 -0400)
committerJoey Hess <joeyh@joeyh.name>
Wed, 26 Feb 2025 18:05:37 +0000 (14:05 -0400)
Command/AddComputed.hs
Command/Recompute.hs
Remote/Compute.hs

index 9ff13f1f70b7067f4731696db6c732b8ccff46eb..f27932405e6367c48b5c0220d1030f2f1b803cc4 100644 (file)
@@ -21,11 +21,9 @@ import Types.KeySource
 import Messages.Progress
 import Logs.Location
 import Utility.Metered
-import Utility.MonotonicClock
 import Backend.URL (fromUrl)
 
 import qualified Data.Map as M
-import Data.Time.Clock
 
 cmd :: Command
 cmd = notBareRepo $ 
@@ -92,17 +90,14 @@ perform o r = do
                , Remote.Compute.computeReproducible = False
                }
        fast <- Annex.getRead Annex.fast
-       starttime <- liftIO currentMonotonicTimestamp
        showOutput
        Remote.Compute.runComputeProgram program state
                (Remote.Compute.ImmutableState False)
                (getInputContent fast)
-               (go starttime fast)
+               (go fast)
        next $ return True
   where
-       go starttime fast state tmpdir = do
-               endtime <- liftIO currentMonotonicTimestamp
-               let ts = calcduration starttime endtime
+       go fast state tmpdir ts = do
                let outputs = Remote.Compute.computeOutputs state
                when (M.null outputs) $
                        giveup "The computation succeeded, but it did not generate any files."
@@ -151,9 +146,6 @@ perform o r = do
                , checkWritePerms = True
                }
        
-       calcduration (MonotonicTimestamp starttime) (MonotonicTimestamp endtime) =
-               fromIntegral (endtime - starttime) :: NominalDiffTime
-       
        isreproducible state = case reproducible o of
                Just v -> isReproducible v
                Nothing -> Remote.Compute.computeReproducible state
index 95f8f3e16ff968bc16ec8f083a8a2e08a9f5883d..42a313ee75b202db8cd160548c72ccacafb68bce 100644 (file)
 module Command.Recompute where
 
 import Command
-import qualified Git
 import qualified Annex
 import qualified Remote.Compute
 import qualified Remote
 import qualified Types.Remote as Remote
 import Annex.CatFile
-import Annex.Content.Presence
 import Annex.Ingest
 import Git.FilePath
-import Types.RemoteConfig
 import Types.KeySource
 import Messages.Progress
 import Logs.Location
 import Utility.Metered
-import Utility.MonotonicClock
 import Backend.URL (fromUrl)
 import Command.AddComputed (Reproducible(..), parseReproducible, getInputContent)
 
 import qualified Data.Map as M
-import Data.Time.Clock
 
 cmd :: Command
 cmd = notBareRepo $ 
@@ -127,12 +122,11 @@ perform o r file key oldstate = do
                , Remote.Compute.computeOutputs = mempty
                }
        fast <- Annex.getRead Annex.fast
-       starttime <- liftIO currentMonotonicTimestamp
        showOutput
        Remote.Compute.runComputeProgram program recomputestate
                (Remote.Compute.ImmutableState False)
                (getinputcontent program fast)
-               (go starttime fast)
+               (go fast)
        next $ return True
   where
        getinputcontent program fast p
@@ -143,9 +137,7 @@ perform o r file key oldstate = do
                                        "requesting a new input file" p
                | otherwise = getInputContent fast p
        
-       go starttime fast state tmpdir = do
-               endtime <- liftIO currentMonotonicTimestamp
-               let ts = calcduration starttime endtime
+       go fast state tmpdir ts = do
                let outputs = Remote.Compute.computeOutputs state
                when (M.null outputs) $
                        giveup "The computation succeeded, but it did not generate any files."
@@ -194,9 +186,6 @@ perform o r file key oldstate = do
                , checkWritePerms = True
                }
        
-       calcduration (MonotonicTimestamp starttime) (MonotonicTimestamp endtime) =
-               fromIntegral (endtime - starttime) :: NominalDiffTime
-       
        isreproducible state = case reproducible o of
                Just v -> isReproducible v
                Nothing -> Remote.Compute.computeReproducible state
index b412fc4df69b9412cfa161c64456858d3a4b88c5..e3ec2a8fddd503b1b86c6b008fea2720fcf15d64 100644 (file)
@@ -41,6 +41,7 @@ import Utility.TimeStamp
 import Utility.Env
 import Utility.Tmp.Dir
 import Utility.Url
+import Utility.MonotonicClock
 import qualified Git
 import qualified Utility.SimpleProtocol as Proto
 
@@ -338,7 +339,7 @@ runComputeProgram
        -> ComputeState
        -> ImmutableState
        -> (OsPath -> Annex (Key, Maybe OsPath))
-       -> (ComputeState -> OsPath -> Annex v)
+       -> (ComputeState -> OsPath -> NominalDiffTime -> Annex v)
        -> Annex v
 runComputeProgram (ComputeProgram program) state (ImmutableState immutablestate) getinputcontent cont =
        withOtherTmp $ \othertmpdir ->
@@ -353,11 +354,13 @@ runComputeProgram (ComputeProgram program) state (ImmutableState immutablestate)
                         , std_out = CreatePipe
                         , env = Just environ
                         }
+               starttime <- liftIO currentMonotonicTimestamp
                state' <- bracket
                        (liftIO $ createProcess pr)
                        (liftIO . cleanupProcess)
                        (getinput state tmpdir subdir)
-               cont state' subdir
+               endtime <- liftIO currentMonotonicTimestamp
+               cont state' subdir (calcduration starttime endtime)
                
        getsubdir tmpdir = do
                let subdir = tmpdir </> computeSubdir state
@@ -435,6 +438,9 @@ runComputeProgram (ComputeProgram program) state (ImmutableState immutablestate)
        checkimmutable False requestdesc p a
                | not immutablestate = a
                | otherwise = computationBehaviorChangeError (ComputeProgram program) requestdesc p
+       
+       calcduration (MonotonicTimestamp starttime) (MonotonicTimestamp endtime) =
+               fromIntegral (endtime - starttime) :: NominalDiffTime
 
 computationBehaviorChangeError :: ComputeProgram -> String -> OsPath -> Annex a
 computationBehaviorChangeError (ComputeProgram program) requestdesc p =
@@ -469,7 +475,7 @@ computeKey rs (ComputeProgram program) k af dest p vc =
                        (keyfile : _) -> Just keyfile
                        [] -> Nothing
 
-       go keyfile state tmpdir = do
+       go keyfile state tmpdir ts = do
                let keyfile' = tmpdir </> keyfile
                unlessM (liftIO $ doesFileExist keyfile') $
                        giveup $ program ++ " exited sucessfully, but failed to write the computed file"